def func(message):
    def getMessage(message):
        print("got a message {}".format(message))

    return getMessage(message)


def func2():
    def printMessage(message):
        print("got a message {}".format(message))

    return printMessage


def my_decorator(func):
    def wrapper():
        print("wrapper of decorator")
        func()

    return wrapper


# 带多个不定参数的装饰器
def withArgsDecorator(func):
    def wrapper(*args, **kwargs):
        print("with args of decorator")
        func(*args, **kwargs)

    return wrapper


@withArgsDecorator
def greetWithName(name):
    print("我是 {}".format(name))


@my_decorator
def my_greet():
    print("hello 我是海贼王路飞")


def generate(k):
    i = 1
    while True:
        yield i ** k
        i += 1


gen_1 = generate(1)
gen_3 = generate(3)


def get_sum(n):
    sum_1, sum_3 = 0, 0
    for i in range(n):
        next1 = next(gen_1)
        next3 = next(gen_3)
        print(f"next1:{next1}next3:{next3}")
        sum_1 += next1
        sum_3 += next3
    print(f"sum1:{sum_1} sum3:{sum_3}")


def findIndex(list, target):
    result = []
    for i, num in enumerate(list):
        if (num == target):
            result.append(i)
    return result


def index_generator(L, target):
    for i, num in enumerate(L):
        if num == target:
            yield i


data = [2201, 1, 5002, 2201, 1982, 4346, 373, 4362, 996, 2199, 882, 5002, 1938, 88, 1940, 999, 4611]

data1 = [2200, 1, 5001, 2200, 1979, 4340, 349, 4354, 997, 2198, 881, 5001, 1933, 108, 1936, 998, 4606]

data2 = [2201, 1, 4999, 2204, 1978, 4342, 396, 4360, 996, 2200, 882, 5002, 1938, 139, 1943, 997, 4601]

hex_string = "151EFC40000400031680122000C80190025103E800E600000042005E00000000000000000300455645000000"


def transformHex2(hex_string):
    # 将16进制字符串分割成4个字符一组
    hex_groups = [hex_string[i:i + 4] for i in range(0, len(hex_string), 4)]

    # 转换每个组为10进制数
    decimal_values = [int(group, 16) for group in hex_groups]

    # 打印结果
    for value in decimal_values:
        print(value)


def moveList(decimal_values, start_pos, end_pos):
    for i in range(start_pos, end_pos):
        decimal_values[i] = decimal_values[i + 1]


def transform2Hex2(hex_string):
    # 初始化结果数组
    decimal_array = []

    # 提取前三个数
    for i in range(3):
        start_index = i * 4
        end_index = start_index + 4
        hex_value = hex_string[start_index:end_index]
        decimal_value = int(hex_value, 16)
        decimal_array.append(decimal_value)

    # 第四个数占用 8个字符

    value4 = int(hex_string[12:20], 16)
    decimal_array.append(value4)
    print(len(decimal_array))

    for i in range(5, 8):
        start_index = (i - 1) * 4 + 4
        end_index = start_index + 4
        hex_value = hex_string[start_index:end_index]
        decimal_value = int(hex_value, 16)
        decimal_array.append(decimal_value)

    value8 = int(hex_string[32:40], 16)
    decimal_array.append(value8)

    print(len(decimal_array))

    for i in range(8, 16):
        start_index = (i - 1) * 4 + 4 * 2
        end_index = start_index + 4
        hex_value = hex_string[start_index:end_index]
        decimal_value = int(hex_value, 16)
        decimal_array.append(decimal_value)

    value17 = int(hex_string[76:84], 16)
    value18 = int(hex_string[84:92], 16)
    decimal_array.append(value17)
    decimal_array.append(value18)

    print(len(decimal_array))

    # 提取最后四个数
    for i in range(19, 25):
        start_index = (i - 1) * 4 + 4 * 4
        end_index = start_index + 4
        hex_value = hex_string[start_index:end_index]
        print(f"{i} {start_index}{hex_value}")
        decimal_value = int(hex_value, 16)
        decimal_array.append(decimal_value)

    print(decimal_array)
    return decimal_array


if __name__ == "__main__":
    # hex_strings1 = [format(num, '04X') for num in data]
    # hex_strings2 = [format(num, '04X') for num in data1]
    # hex_strings3 = [format(num, '04X') for num in data2]
    # result1 = ''.join(hex_strings1)
    # result2 = ''.join(hex_strings2)
    # result3 = ''.join(hex_strings3)
    # print(f"{result1}\n{result2}\n{result3}")
    # gen1 = generate(1)
    # gen2 = generate(2)
    # get_sum(6)
    # print(findIndex([1, 6, 2, 4, 5, 2, 8, 6, 3, 2], 2))
    transformHex2(hex_string)
